package top.someapp.dxf2dsvg.entity;

import top.someapp.dxf2dsvg.base.Point;
import top.someapp.dxf2dsvg.dxf.Item;
import top.someapp.dxf2dsvg.kits.Numbers;

import javax.annotation.Nonnull;

/**
 * @author zwz
 * Created on 2020-04-20
 */
public class Line extends EntityBase {
    private boolean start;
    private Point p1;
    private Point p2;

    public Line() {
        p1 = new Point();
        p2 = new Point();
    }

    @Override
    public String type() {
        return "LINE";
    }

    @Override
    public void setup(@Nonnull Item item) {
//        System.out.println("item in LINE: " + item);
        if (!start && item.code == 100 && item.value.equals("AcDbLine")) {
            start = true;
            return;
        }
        if (start) {
            switch (item.code) {
                case 20:
                    p1.setX(Numbers.floatValue(item.value));
                    break;
                case 30:
                    p1.setY(Numbers.floatValue(item.value));
                    break;
                case 40:
                    p1.setZ(Numbers.floatValue(item.value));
                    break;
                case 21:
                    p2.setX(Numbers.floatValue(item.value));
                    break;
                case 31:
                    p2.setY(Numbers.floatValue(item.value));
                    break;
                case 41:
                    p2.setZ(Numbers.floatValue(item.value));
                    break;
            }
        }
    }

    @Override
    public String toString() {
        return "Line{" +
                "p1=" + p1 +
                ", p2=" + p2 +
                '}';
    }
}
